package com.newedu.equipmgr.service;

import com.newedu.equipmgr.dao.SysPermissionDao;
import com.newedu.equipmgr.dao.SysPermissionDaoImpl;
import com.newedu.equipmgr.entity.SysPermission;
import com.newedu.equipmgr.entity.SysPermissionMenuVO;

import java.util.List;

/**
 * @author jerry
 * @create 2020-06-10 17:22:36
 * @company 新开普电子股份有限公司
 */
public class SysPermissionService {
    private final SysPermissionDao sysPermissionDao = new SysPermissionDaoImpl();


    public boolean insert(SysPermission sysPermission){
        boolean insert = false;
        try{
            insert = sysPermissionDao.insert(sysPermission);
        }
        catch (Exception e){
            throw new RuntimeException("权限信息插入失败！");
        }
        return insert;
    }


    public boolean update(SysPermission sysPermission){
        boolean update = false;
        try{
            update = sysPermissionDao.update(sysPermission);
        }
        catch (Exception e){
            throw new RuntimeException("权限信息更新失败！");
        }
        return update;
    }

    public boolean delete(int id){
        boolean delete = false;
        try{
            delete = sysPermissionDao.delete(id);
        }
        catch (Exception e){
            throw new RuntimeException("权限信息删除失败！");
        }
        return delete;
    }

    public List<SysPermission> selectAll(){
        List<SysPermission> sysRoleList = null;
        try{
            sysRoleList = sysPermissionDao.selectAll();
        }
        catch (Exception e){
            throw new RuntimeException("权限信息查询失败！");
        }
        return sysRoleList;
    }

    public SysPermission selectOne(int id){
        SysPermission sysPermission = null;
        try{
            sysPermission = sysPermissionDao.selectOne(id);
        }
        catch (Exception e){
            throw new RuntimeException("权限信息查询失败！");
        }
        return sysPermission;
    }

    public List<SysPermission> selectBy(String condition, int pageNum, int pageSize){
        List<SysPermission> sysRoleList = null;
        try{
            sysRoleList = sysPermissionDao.selectBy(condition, pageNum, pageSize);
        }
        catch (Exception e){
            throw new RuntimeException("权限信息查询失败！");
        }
        return sysRoleList;
    }

    public int countRows(String condition){
        int rows = 0;
        try{
            rows = sysPermissionDao.countRows(condition);
        }
        catch (Exception e){
            throw new RuntimeException("权限信息总笔数失败！");
        }
        return rows;
    }

    public List<SysPermissionMenuVO> queryPermissionListBy(String userid){
        List<SysPermissionMenuVO> sysPermissionMenuVOList = null;
        try{
            sysPermissionMenuVOList = sysPermissionDao.queryPermissionListBy(userid);
        }
        catch (Exception e){
            throw new RuntimeException("权限信息查询失败！");
        }
        return sysPermissionMenuVOList;
    }
}
